#!/bin/bash




#外网链接
echo '
#NAME			IMG					LINK
Esxi			img/png/esxi.png		https://ffing.fun:250
DSM				img/png/dsm.png			https://ffing.fun:5001
Ikuai			img/png/ikuai.png		https://ffing.fun:251
Istore			img/png/istore.png		http://ffing.fun:252
Jellyfin		img/png/jellyfin.png	http://ffing.fun:8096

Alist			img/png/alist.png		http://cloud.ffing.cn
FFing			img/png/ffing.png		http://ffing.cn
AudioBook		img/png/book.png		http://ffing.fun:13378
天翼云电脑		img/png/tianyiyun.png	tianyiyun://

阿里云			img/png/aliyun.png		https://www.aliyun.com/
腾讯云			img/png/txyun.png		https://cloud.tencent.com/
B站				img/png/bilibili.png	https://space.bilibili.com/376172153
抖音				img/png/douyin.png		https://www.douyin.com/
Youtube			img/png/youtube.png		https://www.youtube.com/
Docker			img/png/docker.png		http://hub.docker.com/

Github			img/png/github.png		https://github.com/
Gitee			img/png/gitee.png		https://gitee.com/ffing/onekey

JD				img/png/jd.png			https://www.jd.com/
TaoBao			img/png/taobao.png		https://www.taobao.com/






' |grep -Ev "^$|^#" >/tmp/wan_link.txt


#内网链接
echo '
Esxi			img/png/esxi.png		https://192.168.68.250
DSM				img/png/dsm.png			https://192.168.68.253:5001
Ikuai			img/png/ikuai.png		https://192.168.68.251:251
Istore			img/png/istore.png		http://192.168.68.250
AudioBook		img/png/book.png		http://192.168.68.253:13378
Win10			img/png/win7.png		vmrc://192.168.68.250/?moid=124
天翼云电脑		img/png/tianyiyun.png	tianyiyun://
青龙面板			img/png/qinglong.png	http://192.168.68.253:5700
Jellyfin		img/png/jellyfin.png	http://192.168.68.253:8096
Alist			img/png/alist.png		http://cloud.ffing.cn
FFing			img/png/ffing.png		http://ffing.cn




' |grep -Ev "^$|^#" >/tmp/lan_link.txt

############################################################
#判断是macos或linux？
#sh
uname -a |grep Darwin >/dev/null
if [ $? -eq  0 ];then
	echo "当前macos"
	#判断是否安装greadlink
	greadlink --help >/dev/null 2>&1
	if [ ! $? -eq 0 ];then
		echo "开始安装coreutils"
		brew install coreutils
		if [ ! $?  -eq 0 ];then echo "macos安装coreutils失败，无法使用greadink命令，请手动安装！";exit;fi
	fi
	SHPATH=`greadlink -f $0`
else
	echo "当前linux"
	SHPATH=`readlink -f $0`
fi
SHDIR=`dirname $SHPATH`



#cp
\cp $SHDIR/index.demo.html $SHDIR/index.html



################ wan链接 ####################

###wan-head
WAN_HEAD_NUM=`cat -n $SHDIR/index.html|grep  'WAN开始'|awk  '{print $1}'`
sed -n "1,$WAN_HEAD_NUM"p $SHDIR/index.html > /tmp/wan_head.txt
###wan-foot
WAN_FOOT_NUM=`cat -n $SHDIR/index.html|grep  'WAN结束'|awk  '{print $1}'`
sed -n "$WAN_FOOT_NUM,$"p $SHDIR/index.html > /tmp/wan_foot.txt
###wan-li
>/tmp/wan_li.txt
#
while read WAN
do
WAN_NAME=`echo $WAN|awk '{print $1}'`
WAN_IMG=`echo  $WAN|awk '{print $2}'`
WAN_LINK=`echo $WAN|awk '{print $3}'`
echo "<li><a href='$WAN_LINK' target='_blank'><img class='shake' src='$WAN_IMG' /><strong>$WAN_NAME</strong></a></li>" >> /tmp/wan_li.txt
done < /tmp/wan_link.txt

cat /tmp/wan_head.txt /tmp/wan_li.txt /tmp/wan_foot.txt > $SHDIR/index.html



################ LAN链接 ####################
###lan-head
LAN_HEAD_NUM=`cat -n $SHDIR/index.html|grep  'LAN开始'|awk  '{print $1}'`
sed -n "1,$LAN_HEAD_NUM"p $SHDIR/index.html > /tmp/lan_head.txt
###wan-foot
LAN_FOOT_NUM=`cat -n $SHDIR/index.html|grep  'LAN结束'|awk  '{print $1}'`
sed -n "$LAN_FOOT_NUM,$"p $SHDIR/index.html > /tmp/lan_foot.txt
###wan-li
>/tmp/lan_li.txt
#
while read LAN
do
LAN_NAME=`echo $LAN|awk '{print $1}'`
LAN_IMG=`echo  $LAN|awk '{print $2}'`
LAN_LINK=`echo $LAN|awk '{print $3}'`
echo "<li><a href='$LAN_LINK' target='_blank'><img class='shake' src='$LAN_IMG' /><strong>$LAN_NAME</strong></a></li>" >> /tmp/lan_li.txt
done < /tmp/lan_link.txt

cat /tmp/lan_head.txt /tmp/lan_li.txt /tmp/lan_foot.txt > $SHDIR/index.html



